﻿using System;
using ServiceStack;

using GameTools;

namespace PuSuoPai
{
	class MainClass
	{
		static void  CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
		{
			Log.WriteLog(string.Format("应用程序出现异常，请重新启动！异常情况如下:\r\n{0}", e.ExceptionObject.ToString()));


			Environment.Exit(0); //0代表正常退出，非0代表某种错误的退出
		}

		public static void Main (string[] args)
		{
			AppDomain.CurrentDomain.UnhandledException +=new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException);

			string url = "http://120.27.34.224:1337/";
			string localUrl = "http://127.0.0.1:1337/";
			var appHost = new HelloServiceHost()
				.Init()
				.Start(localUrl);

			Console.WriteLine("AppHost Created at {0}, listening on {1}", DateTime.Now, localUrl);

			Console.ReadKey();
		}
	}

	public class HelloServiceHost : AppSelfHostBase
	{
		/// <summary>
		/// Default constructor.
		/// Base constructor requires a name and assembly to locate web service classes. 
		/// </summary>
		public HelloServiceHost()
			: base("PuSuoPai Web Services", typeof(PuSuoPaiService).Assembly)
		{

		}

		/// <summary>
		/// Application specific configuration
		/// This method should initialize any IoC resources utilized by your web service classes.
		/// </summary>
		/// <param name="container"></param>
		public override void Configure(Funq.Container container)
		{
			//Config examples
			//this.AddPlugin(new PostmanFeature());
			//this.AddPlugin(new CorsFeature());
		}
	}
}
